const BaseRest = require('./rest.js');
const Mock = require('mockjs');

//const menus = require('../init_data/menu.js');
/**
 * 生成测试数据
 *
 * @type {module.exports}
 */
module.exports = class extends BaseRest {
  constructor(ctx) {
    super(ctx);
    this.modelInstance = this.model('menu');
  }
  
  async getAction() {
    
    let menus = await think.cache('ADMIN_MENU', async () => {
      think.logger.debug('重新从数据库加载菜单文件');
      return await this.model('menu').getMenus('framework');
    }, {
      timeout: 60 * 60 * 1000, //60分钟
    });
    
    think.logger.debug(menus)
    return this.success(menus);
  }
  
  async postAction() {
    return this.fail('不能调用该接口');
  }
  
  async putAction() {
    return this.fail('不能调用该接口');
  }
  
  async deleteAction() {
    return this.fail('不能调用该接口');
  }
  
  async patchAction() {
    return this.fail('不能调用该接口');
  }
  
  //async postAction() {
  //  await this.model('menu').where(true).delete();
  //  await this.model('menu').makeMenus(require('../init_data/menu.js'), 'framework');
  //  return this.success('生成模拟数据成功！');
  //}
  
};
